package cn.cn.tedu.file;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;
import java.util.Scanner;

/**
 * @author ：Dsi
 * @date ：2021/11/16 14:11
 * Describe ：该类用于测试字节输出流
 */
public class TestOut {
    public static void main(String[] args) {
        //method1();
        method3();

    }

    private static void method3() {
        BufferedOutputStream b=null;
        try {
            b=new BufferedOutputStream(new FileOutputStream("D:\\ready\\1.txt",true));
            b.write(45);

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                b.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }




    private static void method1() {
        FileOutputStream o=null;
        try {

            o = new FileOutputStream("D:\\ready\\1.txt",new File("D:\\ready\\1.txt").length() !=0);

            File o1=new File("D:\\ready\\1.txt");
            o = new FileOutputStream(o1,o1.length()!=0);

            int c=0;
            while (c<10){
                //o.write((int) (Math.random()*100+1));
                o.write(new Random().nextInt(100));
                c++;
            }



        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try{
                o.close();
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}
